package com.argushealth.huang.cglib;

import java.lang.reflect.Method;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

/**
 * 
 * @author guozhuhuang
 *
 */
public class ProxyAgent implements MethodInterceptor {
	private Person person;
	
	public Object getInstance(Person person) {
		this.person = person;
		Enhancer enhancer = new Enhancer();
		enhancer.setCallback(this);
		enhancer.setSuperclass(person.getClass());
		return enhancer.create();
	}

	public Object intercept(Object arg0, Method arg1, Object[] arg2, MethodProxy arg3) throws Throwable {
		System.out.println("------------------华丽的分割线----------------");
//		Object result = arg3.invokeSuper(arg0, arg2);
		Object result = arg3.invoke(this.person, arg2);
		System.out.println("------------------华丽的分割线----------------");
		return result;
	}
}
